<?php

class videoComponents extends sfComponents
{
    /**
     * 杂志报道列表
     * @return void
     */
    public function executeMrl()
    {
        /*$this->mazines=Doctrine_Core::getTable("Magzine")->createQuery()->execute();
        $this->tttsss=$this->hhh;
        $this->ddd=$this->hhhd;*/
    }

    public function executeRelatedlive()
    {
        $record_Count=3;
        if(!empty($this->recordCount))
            $record_Count=$this->recordCount;
        $execsql= Doctrine_Core::getTable("video")->createQuery('c');
        if(!empty($this->videoType)){
            $video_type=$this->videoType;
            $execsql=$execsql->where("c.sub_catalog_id='".$video_type."'");
         }
        if(!empty($this->keyword)){
            $keyword=$this->keyword;
            $execsql=$execsql->andWhere("c.keyword like '%".$keyword."%'");
         }
        $execsql=$execsql->andWhere("status_id=1005");
        $this->videos=@$execsql->orderBy('c.publish_time desc')
                ->limit($record_Count)
                ->execute();
    }
    /**
     *最新视频列表
     */
    public function executeLvl()
    {
      /*  $sql=Doctrine_Core::getTable("video");//->createQuery('c')->orderBy('c.video_id desc');
        $this->videos=$sql->execute();*/

        $this->videos=Doctrine_Core::getTable("video")->createQuery('c')->orderBy('c.video_id desc')->execute();
    }

    /*
     * 视频组播放列表
     */
    public function executeGvl()
    {
        //$this->videos=Doctrine_Core::getTable("video")->createQuery('c')->orderBy('c.video_id desc')->execute();
        // $baseVideo=new ArticleTable("");
        $this->pagevideos=Doctrine_Core::getTable("video")->createQuery('c')->orderBy('c.video_id desc')->execute();

    }

    public function executeSvl2()
    {
        //"video"
        $this->svl2videos=Doctrine_Core::getTable("video")->createQuery('v')->limit(4)->where('v.video_id>?','1123')->orderBy('v.video_id desc') ->execute() ;
    }

    public function executeRvl1()
    {
        //select top 4 * from video where tag like '%%' and video_id!=1000 order by video_id desc
        $this->rvl1videos=Doctrine_Core::getTable("video")->createQuery('v')->limit(4)->where("v.tag like '%%' and v.video_id!=1000")->orderBy('v.video_id desc') ->execute() ;
    }

    public function executeRvl2()
    {
        //select top 4 * from video where tag like '%%' and video_id!=1000 order by video_id desc
        $this->rvl2videos=Doctrine_Core::getTable("video")->createQuery('v')->limit(10)->where("v.tag like '%%' and v.video_id!=1000")->orderBy('v.video_id desc') ->execute() ;
    }

    public function executeHvl()
    {
        $this->hvlVideos=Doctrine_Core::getTable("video")->createQuery('v')->where("status_id=1005")->limit(10) ->execute() ;
    }

    public function executeRsl2()
    {
        $this->Rsl2Videos=Doctrine_Core::getTable("video")->createQuery('v')->where("status_id=1005")->limit(10) ->execute() ;
    }
    
    public function executeCesh()
    {
        /* $query = Doctrine_Query::create()->from("Video v")
             ->leftJoin('RecommendContent r')
             ->Where('v.video_id=r.content_id')*/
         //    ->andWhere('sub_catalog_id='.$this->subCatalogId)
         //    ->orderBy('v.publish_time desc,v.video_id desc');
        $query="select * from video where status_id=1005";
        $conn = Doctrine_Manager::connection();
        $statement=$conn->execute($query);
        $statement->setFetchMode(PDO::FETCH_ASSOC);
        $this->ceshis=$statement->fetch();//$query->execute();
    }

    public function executeScene()//rvl1
    {
        $this->Rsl2Videos=Doctrine_Core::getTable("video")->createQuery('v')->where("status_id=1005")->limit(10) ->execute() ;
    }

    public function executeHotlink()//rvl1
    {
        if(null==$this->recordCount||""==$this->recordCount)
            $this->recordCount=10;
        if(null==$this->catalogId)
            $this->catalogId="";
        $period=" publish_time desc";
         //$period=" (hit_i+hit_mask_i) desc";
        switch($this->period)
        {
            case "daily":
                 $period="daily_hit desc";
                break;
            case "weekly":
                 $period="weekly_hit desc";
                break;
            case "monthly":
                 $period="monthly_hit desc";
                break;
            default:
                break;
        }
       // $sqlExec = Doctrine_Core::getTable("video")->createQuery('v');
        //if(""!=$this->catalogId)
             //$sqlExec=$sqlExec ->where('catalog_id='.$this->catalogId );
        $this->Videos=Doctrine_Core::getTable("video")->createQuery('v')
                ->where("status_id=1005")
                ->orderBy($period)
                ->limit($this->recordCount) 
                ->execute() ;
    }

    public function executePlaylist()
    {
        $this->Videos=Doctrine_Core::getTable("video")->createQuery('v')->where('prim_video_group_id='.$this->groupid)->andWhere("status_id=1005")->limit(4) ->execute();
    }

    public function executeEspecially()
    {
        $this->Rsl2Videos=Doctrine_Core::getTable("video")->where("status_id=1005")->createQuery('v')->limit(10) ->execute() ;
    }

    public function executeRelated()
    {
        if(!empty($this->recordCount))
            $record_Count=$this->recordCount;
        if(!empty($this->contentTypeId))
            $contentTypeId=$this->contentTypeId;

        $this->videoArray = array();
        //$this->moreLinkDisplay=$request->getParameter("moreLinkDisplay","none");
        $sqlStr = "select  video_id,title, artist,snapshot_big, keyword from video where status_id=1005 and video_id in(select r_content_id from RelatedContent where r_content_type_i = 1001 and content_type_i=". $this->contentTypeId." and content_id=".$this->contentId;
        if(isset($this->catalogId) == true)
	       $sqlStr = $sqlStr." and catalog_id=".$this->catalogId;
        $sqlStr = $sqlStr.") order by publish_time desc, video_id desc limit ".$this->recordCount;
        $this->videoArray=DbBase::getDataQuery($sqlStr);
    }

    public function executeLatest()
    {
        $this->Videos=Doctrine_Core::getTable("video")->createQuery('v')->where("status_id=1005")->orderBy('publish_time desc')->limit(6) ->execute() ;
    }

    public function executeRecommend()
    {
        $recordCount=$this->recordCount;
        $catalogId=$this->catalogId;
        $this->layout=$this->layout;
        if(null==$recordCount||""==$recordCount)
            $recordCount=5;
        if(null==$catalogId||""==$catalogId)
            $catalogId=1000;
        if(1==$this->layout)
        {
            $this->chinVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1000')->andWhere("status_id=1005")->orderBy('publish_time desc')->limit($recordCount) ->execute() ;
            $this->kpopVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1001')->andWhere("status_id=1005")->orderBy('publish_time desc')->limit($recordCount) ->execute() ;
            $this->jpopVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1002')->andWhere("status_id=1005")->orderBy('publish_time desc')->limit($recordCount) ->execute() ;
            $this->westVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1003')->andWhere("status_id=1005")->orderBy('publish_time desc')->limit($recordCount) ->execute() ;
        }else{
            $this->Videos=Doctrine_Core::getTable("video")->createQuery('v')->limit($recordCount)->where('catalog_id='.$catalogId)->andWhere("status_id=1005") ->orderBy('publish_time desc')->execute() ;
        }
    }

    public function executeSpecial()
    {
        $counts="4";
        if(!empty($this->recordCount))
            $counts=$this->recordCount;
        $this->chinVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1000')->andWhere("status_id=1005")->limit($counts) ->execute() ;
        $this->kpopVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1001')->andWhere("status_id=1005")->limit($counts) ->execute() ;
        $this->jpopVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1002')->andWhere("status_id=1005")->limit($counts) ->execute() ;
        $this->westVideos=Doctrine_Core::getTable("video")->createQuery('v')->where('catalog_id=1003')->andWhere("status_id=1005")->limit($counts) ->execute() ;
    }

    public function executeList()
    {

        $this->Rsl2Videos=Doctrine_Core::getTable("video")->createQuery('v')->where("status_id=1005")->limit(10) ->execute() ;
    }
}